package com.zhilianbao.leyaogo.ui.adapter.me;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bql.recyclerview.swipe.SwipeMenuAdapter;
import com.zhilianbao.leyaogo.R;

import java.util.List;

/**
 * Created by liu on 2016/10/29.
 * 系统消息的adapter
 */
public class MesAdapter extends SwipeMenuAdapter<MesAdapter.MesViewHolder> {
    private List mList;
    private Context mContext;

    public MesAdapter(Context context, List list) {
        mList = list;
        this.mContext = context;
    }

    @Override
    public View onCreateContentView(ViewGroup parent, int viewType) {
        return LayoutInflater.from(parent.getContext()).inflate(R.layout.fragment_message, parent, false);
    }

    @Override
    public MesViewHolder onCompatCreateViewHolder(View realContentView, int viewType) {
        return new MesViewHolder(realContentView);
    }

    @Override
    public void onBindViewHolder(MesViewHolder holder, int position) {
        holder.setData(mContext, position);

    }

    @Override
    public int getItemCount() {
        return 2;/*mList == null ? 0 : mList.size();*/
    }


    static class MesViewHolder extends RecyclerView.ViewHolder {

        private final TextView mContent;
        private final TextView mTitle;
        private final TextView mNum;
        private final ImageView mIvMesIcon;

        public MesViewHolder(View itemView) {
            super(itemView);
            mTitle = (TextView) itemView.findViewById(R.id.tv_mes_title);
            mContent = (TextView) itemView.findViewById(R.id.tv_mes_content);
            mNum = (TextView) itemView.findViewById(R.id.tv_mes_num);
            mIvMesIcon = (ImageView) itemView.findViewById(R.id.iv_mes_icon);
        }

        public void setData(Context context, int position) {
            if (position==0) {
                mTitle.setText("系统消息");
                mContent.setText("大家快点来");
                mIvMesIcon.setImageResource(R.drawable.ic_message_system);
                mNum.setText("3");
            }else if (position==1) {
                mTitle.setText("优惠券消息");
                mContent.setText("您的优惠券快过期,请您快点使用");
                mIvMesIcon.setImageResource(R.drawable.ic_message_privilege);
                mNum.setText("24");
            }
        }
    }
}